<template>
  <div>
    <el-table
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column
        fixed
        prop="sno"
        label="学生编号"
        width="100">
      </el-table-column>

      <el-table-column
        prop="cno"
        label="课程号"
        width="100">
      </el-table-column>
      <el-table-column
        prop="cname"
        label="科目名"
        width="100">
      </el-table-column>
      <el-table-column
        prop="tno"
        label="教师号"
        width="100">
      </el-table-column>
      <el-table-column
        prop="cperiod"
        label="学时"
        width="100">
      </el-table-column>
      <el-table-column
        prop="cclassperiod"
        label="上课周期"
        width="100">
      </el-table-column>
      <el-table-column
        prop="cprice"
        label="收费"
        width="100">
      </el-table-column>
      <el-table-column
        prop="csite"
        label="上课地点"
        width="100">
      </el-table-column>
      <el-table-column
        prop="cneed_stu"
        label="招收人数"
        width="100">
      </el-table-column>
      <el-table-column
        prop="cnum_stu"
        label="已报名人数"
        width="100">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="handleEdit(scope.row)">编辑</el-button>
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next"
      page-size="6"
      :total="total"
      @current-change="page">
    </el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        tno: '',
        tname: '',
        tlever: '',
        tspecialty: '',
      },
      total:null,
      tableData: null,
      rules: {
        tname: [
          { required: true, message: '教师名字不能为空', trigger: 'blur' }
        ],
        tlever: [
          { required: true, message: '教师等级不能为空', trigger: 'blur' }
        ],
        tspecialty : [
          { required: true, message: '教师特长不能为空', trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      const _this = this;
      this.$refs[formName].validate((valid) => {
        if (valid) {
          axios.post('http://localhost:8181/sc/save',this.ruleForm).then(function (resp) {
            if(resp.data == 'success'){
              _this.$alert(_this.ruleForm.tname+'添加成功！', '消息', {
                confirmButtonText: '确定',
                callback: action => {
                  _this.$router.push('/TeacherImformation')
                }
              })
            }
          })
        } else {
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },

  },
  created() {
    const _this = this;
    axios.get('http://localhost:8181/sc/findAll/1/6').then(function (resp) {
      _this.tableData = resp.data.content
      _this.total = resp.data.totalElements
    })
  }
}
</script>
